<?php
namespace Home\Service;

use Think\Service\BasicService;

class APIService extends BasicService {
    public function insert($model) {
        return $this->db->add($model);
    }

    public function AddAll($model) {
        $data = $this->db->addAll($model);
        return $data;
    }

    public function remove($condition) {
        return $this->db->where($condition)->delete();
    }

    public function update($where, $model = array()) {
        return $this->db->where($where)->save($model);
    }

    public function find($condition, $field = '*', $top = 0) {
        $IMGDATA = $this->db->join('ts_book_img on ts_book_img.BOOK_ID = ts_book.ID')->where($condition)->field('ts_book_img.IMG_URL')->select();
        $DATA = $this->db->where($condition)->field($field)->find();
        if ($top) {
            $DATA['IMG_URLS'] = $IMGDATA;
        }
        return $DATA;
    }

    public function query($condition, $limit = array(), $field = '*', $order = null) {
        $data = $this->db->field($field)->where($condition)->limit($limit['start'], $limit['end'])->order($order)->select();
        //        return $this->db->_sql();
        return $data;
    }

    public function query1($condition, $limit = array(), $field = '*', $order = null) {
        $data = $this->db->field($field)->where($condition)->limit($limit['start'], $limit['end'])->order($order)->select();
        //               return $this->db->_sql();
        return $data;
    }


    public function count($condition) {
        return $this->db->where($condition)->count();
    }

    public function GetBookInfo($condition) {
        $data = $this->db->join('')->where($condition)->field()->find();
        return $data;
    }


    public function ZNquery($where) {
        $SQL = "SELECT ID as book_id,TITLE as book_name," . "PIC_URL as book_img,Y_PRICE as book_old_money," . "XS_PRICE as book_pay_money,ZN_PRICE as book_overdue_fine,`INFO`" . "FROM `ts_book`" . "WHERE `SXJ` = 1 " . "AND (`region_one` LIKE '%" . $where['THEME'] . "%' OR `region_two` LIKE '%" . $where['THEME'] . "%' OR  `region_two` LIKE '%" . $where['type2'] . "%' OR   `KEY` LIKE '%" . $where['THEME'] . "%')" . "AND `AUTHOR` LIKE '%" . $where['type3'] . "%'" . "AND `AGE` LIKE '%" . $where['AGE'] . "%' " . "LIMIT 0," . $where['NUM'];
        $DATA = $this->db->query($SQL);
        return $DATA;
    }


}

?>